part of 'card.dart';

class _InitialMemorizationCardWloc
    extends StatefulWloc<_InitialMemorizationCardWlocState, InitialMemorizationCard>
    with CardWlocMixin {
  late final bloc.InitialMemorizationCardBloc _bloc;

  @override
  _InitialMemorizationCardWlocState get initialState {
    return _InitialMemorizationCardWlocState(
      lexicalItem: widget.lexicalItem,
      dialect: widget.dialect,
      safeToPronounce: widget.safeToPronounce,
      imagePath: widget.imagePath,
    );
  }

  void onPronunciationCautionButtonPressed() {
    showPronunciationCautionDialog(
      context: context,
    );
  }

  void onLexicalItemPronunciationButtonPressed() {
    _bloc.requestLexicalItemPronunciation();
  }

  void onContinuationButtonPressed() {
    widget.onContinuationButtonPressed();
  }

  void onLexicalItemUseCasePronunciationButtonPressed(LexicalItemUseCase lexicalItemUseCase) {
    _bloc.requestLexicalItemUseCasePronunciation(
      lexicalItemUseCase: lexicalItemUseCase,
    );
  }

  @override
  void didUpdateWidget(InitialMemorizationCard oldWidget) {
    super.didUpdateWidget(oldWidget);

    final updatedState = _InitialMemorizationCardWlocState(
      lexicalItem: widget.lexicalItem,
      dialect: widget.dialect,
      safeToPronounce: widget.safeToPronounce,
      imagePath: widget.imagePath,
    );

    emit(updatedState);

    if (oldWidget.lexicalItem != widget.lexicalItem) {
      _bloc.updateLexicalItem(
        lexicalItem: widget.lexicalItem,
      );
    }
  }

  @override
  void initState() {
    super.initState();

    _bloc = bloc.InitialMemorizationCardBloc(
      lexicalItem: widget.lexicalItem,
      pronounceLexicalItem: initial_memorization_card_di.sl(),
      pronounceLexicalItemUseCase: initial_memorization_card_di.sl(),
    );
  }

  @override
  void dispose() {
    _bloc.close();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _InitialMemorizationCardView(
      wloc: this,
    );
  }
}
